package com.wtwd.campus.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wtwd.campus.entity.HbDxE15RyAuth;
import com.wtwd.campus.entity.HbDxE15RyPushEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.Map;
import java.util.Random;

/**
 * @author mjy
 * @date 2022/08/24
 * @description
 */
public class HbDxE15RyUtiils {


    private static final Logger logger = LoggerFactory.getLogger(HbDxE15RyUtiils.class);

    private static String APP_KEY = "ry202209130940";

    private static String APP_SECRET = "8bbbde60fca04cabafb30eefb4f9b25ec1537552c9cc0b6";

    private static String PUSH_URL="https://dzxsz.tsp189.com/prod-api/wxMsg/wxMsgPush";

    public static final String allChar = "0123456789";

    public static void hbDxE15RyPush(HbDxE15RyPushEntity hbDxE15RyPushEntity) {
        HbDxE15RyAuth hbDxE15RyAuth = new HbDxE15RyAuth();
        hbDxE15RyAuth.setAppId(APP_KEY);
        hbDxE15RyAuth.setAppSecret(APP_SECRET);
        hbDxE15RyPushEntity.setMsgHead(JSONObject.toJSONString(hbDxE15RyAuth));
        hbDxE15RyPushEntity.setdName("智能学生证:"+hbDxE15RyPushEntity.getImei());
        hbDxE15RyPushEntity.setTstamp(String.valueOf(new Date().getTime()).concat(generateStr(5)));
        Map data = JSON.parseObject(JSON.toJSONString(hbDxE15RyPushEntity), Map.class);
        logger.info("send hbDxE15RyPush param={}",data.toString());
        System.out.println(data);
        String s = HttpclientUtil.get(PUSH_URL, data,"UTF-8");
        logger.info("reply hbDxE15RyPush param={}",s);
        return;
    }

    public static void main(String[] args) {
        HbDxE15RyPushEntity hbDxE15RyPushEntity = new HbDxE15RyPushEntity();
        hbDxE15RyPushEntity.setImei("862616050002013");
        hbDxE15RyPushEntity.setdName("【862616050002013】");
        hbDxE15RyPushEntity.setmType("1");
        hbDxE15RyPushEntity.setmClass("1");
        hbDxE15RyPushEntity.setmTime("2022-05-24 12:00:00");
        hbDxE15RyPushEntity.setMemo("我是一个备注");
        hbDxE15RyPushEntity.setTstamp("165398707700015963");
        hbDxE15RyPush(hbDxE15RyPushEntity);
    }

    /**
     * 获取随机字符串
     *
     * @param len
     * @return
     */
    public static String generateStr(int len) {
        StringBuffer sb = new StringBuffer();
        Random random = new Random();
        for (int i = 0; i < len; i++) {
            sb.append(allChar.charAt(random.nextInt(allChar.length())));
        }
        return sb.toString();
    }

}
